package com.core.a.sample;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


public class ComparatorTest {
    public static void main(String[] args)  {
        List<Employee> employees = new ArrayList<Employee>();
        employees.add(new Employee(2, "CCC"));
        employees.add(new Employee(1, "BBB"));
        employees.add(new Employee(3, "AAA"));
        Collections.sort(employees,new NameComparator());
        for(Employee e : employees){
            e.display();
        }
    }
}
class IdComparator implements Comparator<Employee>{
    public int compare(Employee e1, Employee e2){
        return e1.id - e2.id;
    }
}
class NameComparator implements Comparator<Employee>{
    public int compare(Employee e1, Employee e2){
        return e1.name.compareTo(e2.name);
    }
}

class Employee{
    int id;
    String name;

    public Employee(int id, String name) {
        this.id = id;
        this.name = name;
    }
    public void display(){
        System.out.println(id + " : " + name);
    }
}